#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char *argv[]){
    
    char * arreglo[100];
    char * logname;    
    char buf[1024];
    int i;
 
    while(1){  
		
        char * path = (char *) getcwd(NULL, 0); //Encuentra el pwd
        logname = getenv ("LOGNAME");	//Encuentra el logname
        printf("%s # %s > ",logname,path);
                        
        if ((fgets(buf, 1024, stdin) == NULL) || (strcmp(buf,"exit\n")==0)) return 0;
			else{ 
                 printf("%s",buf);
                 
                 arreglo[0]= strtok(buf," \n");
                 
                 i=1;
				 while (arreglo[i] != NULL){
					arreglo[i]= strtok(NULL," \n");
					i++;
				}
					
				if(strcmp(arreglo[0],"cd")==0){
						if(chdir(arreglo[1])!=0)printf("Command not found\n");
						else path=(char *) getcwd(NULL,0);
				}
                
            }
    }
        
    return 0;
}
